package com.vehicle.controller;


import com.vehicle.bean.Car;
import com.vehicle.service.CarService;
import com.vehicle.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 校园车辆管理系统
 * @since 2023-05-14
 */
@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    CarService carService;


    @GetMapping("/allList/{page}/{size}")
    public ResultVO getAllList(@PathVariable("page") String page,@PathVariable("size") String size){
       return ResultVO.succ(carService.getAllCar(Integer.parseInt(page),Integer.parseInt(size)));
    }

    @GetMapping("/userHave/{userId}")
    public ResultVO userHave(@PathVariable("userId") Integer userId){
        boolean b = carService.UserExist(userId);
        if(b){
            return ResultVO.succ("有");
        }
        return ResultVO.fail("没有");
    }

    //根据车牌号搜索车辆信息
    @GetMapping("/getMessageByName/{name}")
    public ResultVO getMessageByName(@PathVariable("name") String name){
        System.out.println("没有来吗");
        Car car = carService.getMessageByName(name);
        System.out.println("car出来了吗");
        System.out.println(car);
        if(car !=null){
            return ResultVO.succ(car);
        }
        return ResultVO.fail("wuwuuw");
    }

    //根据用户id查出车辆信息
    @GetMapping("/getMessageByUserId/{userId}")
    public ResultVO getMessageByUserId(@PathVariable("userId") Integer userId){
        System.out.println("没有来吗");
        System.out.println(userId);
        Car car = carService.getMessageByUserId(userId);
        System.out.println("car出来了吗");
        System.out.println(car);
        if(car !=null){
            return ResultVO.succ(car);
        }
        return ResultVO.fail("wuwuuw");
    }


    @GetMapping("/getCategoryId/{userId}")
    public ResultVO getCategoryId(@PathVariable("userId") Integer userId){

        return ResultVO.succ(carService.getCategory(userId));
    }

}

